package com.s4j.struts.biz.interceptor;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.s4j.core.conset.Constant;
import com.s4j.core.manager.model.SysUser;

public class BgLoginInterceptor extends AbstractInterceptor {

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext ctx = invocation.getInvocationContext();
		Map session = (Map)ctx.getSession();
        HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
        String contextPath = request.getContextPath();
        HttpServletResponse response = (HttpServletResponse)ctx.get(ServletActionContext.HTTP_RESPONSE);
		SysUser user = (SysUser)session.get(Constant.BG_LOGIN_USER);
		if(user == null) {
			response.sendRedirect(contextPath + "/managerLogin/toLogin.do");
		}
		return invocation.invoke();
	}

}
